<template>
    <!-- 修改资料 -->

    <div>
        <!--  v-if="visible"  @click.self="handleClose" -->
        <!-- 内容主题区域 -->
        <el-form label-width="100px" :model="form" label-position="right" ref="formRef" :rules="formRules" disabled
            class="borderNone">
            <el-card>
                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="5" :xl="5">
                        <el-form-item label="评审表编号" prop="number">
                            <el-input v-model="form.number"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="9" :xl="9">
                        <el-form-item label="发行日期" prop="releaseDate">
                            <el-row :gutter="10">
                                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                                    <el-input v-model="form.releaseDate" />
                                </el-col>
                                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                                    <el-input v-model="form.releaseHour" />
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="5" :xl="5">
                        <el-form-item label="完成期限" prop="completeDays">
                            <el-input v-model="form.completeDays" type="number">个工作日</el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="5" :xl="5">
                        <el-form-item label="版本号" prop="sampleVersion">
                            <el-input v-model="form.sampleVersion"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
                        <el-form-item label="图号" prop="drawingNo">
                            <el-input v-model="form.drawingNo"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
                        <el-form-item label="数量" prop="amount">
                            <el-input v-model="form.amount"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
                        <el-form-item label="炭刷规格" prop="carbonBrushSpec">
                            <el-input v-model="form.carbonBrushSpec">个工作日</el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
                        <el-form-item label="客户名称" prop="custName">
                            <el-input v-model="form.custName"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-card>
        </el-form>
        <el-card style="margin-top: 20px;">
            <sc-title title="权限设置"></sc-title>
            <el-scrollbar height="400px">
                <el-form-item prop="column">
                    <ts-form-table v-model="dataList" :addTemplate="addTemplate"  drag-sort placeholder="暂无数据"
                        @updateIndex="updateIndex">
                        <template #tableContent>
                            <el-table-column label="姓名" width="300px">
                                <template #default="scope">
                                    <sc-table-select v-model="scope.row.readerRow" :inputWidth="250" :apiObj="apiObj"
                                        :fileName="readerFileName" :table-width="700" :props="tableProps"
                                        :defaultSelected="scope.row.readName" @change="readerChange(scope.row, $event)">
                                    </sc-table-select>
                                </template>
                            </el-table-column>
                            <el-table-column prop="deptName" label="部门名称" width="200">
                            </el-table-column>
                            <el-table-column prop="editAuthority" label="修改权限">
                                <template #default="scope">
                                    <el-switch v-model="scope.row.editAuthority" active-value="1" inactive-value="0">
                                    </el-switch>
                                </template>
                            </el-table-column>
                            <el-table-column prop="deleteAuthority" label="删除权限">
                                <template #default="scope">
                                    <el-switch v-model="scope.row.deleteAuthority" active-value="1" inactive-value="0">
                                    </el-switch>
                                </template>
                            </el-table-column>
                            <el-table-column prop="endAuthority" label="结案权限">
                                <template #default="scope">
                                    <el-switch v-model="scope.row.endAuthority" active-value="1" inactive-value="0">
                                    </el-switch>
                                </template>
                            </el-table-column>
                            <el-table-column prop="editReaderAuthority" label="修改查阅者权限">
                                <template #default="scope">
                                    <el-switch v-model="scope.row.editReaderAuthority" active-value="1" inactive-value="0">
                                    </el-switch>
                                </template>
                            </el-table-column>
                        </template>
                    </ts-form-table>
                </el-form-item>
            </el-scrollbar>
        </el-card>

        <div class="button-position" style="margin-top: 5px;">
            <el-button @click="updateVisible">取 消</el-button>
            <el-button @click="update" type="primary">确 定</el-button>
        </div>
    </div>
</template>

<script setup>
import { reactive, ref, onMounted } from 'vue';
import { ElNotification } from 'element-plus';
import Api from '@/api/model/sample'
import sysApi from '@/api/model/system'
import tsFormTable from '@/components/scFormTable/index.vue'
const emit = defineEmits(['updatetable'])
const props = defineProps({
    paramsData: {
        type: Object,
        defalut: {}
    }
})
// 添加用户数据的对象
const form = ref({})
const dataList = ref([])
const formRef = ref()
const readerRow = ref({})
const addTemplate = ref({
})
const tableProps = {
    label: 'name',
    value: 'id',
}
const apiObj = ref(sysApi.select.query)
const readerFileName = ref('EmployeeReport')
onMounted(() => {
    getInit()
})
const getInit = async () => {
    let res = await Api.audittable.editReader.post(props.paramsData)
    if (res.code == '200') {
        form.value = res.data
        form.value.carbonBrushSpec = form.value.carbonBrushSpec.split(",").join("")
        dataList.value = res.dataList
        addTemplate.value = res.dtl
    }

}
const updateIndex = () => {
    dataList.value.forEach((item, index) => {
        item.itemIndex = index + 1
    })
}
const readerChange = (prop, val) => {
    prop.readerId = val.id
    prop.readerName = val.name
    prop.deptName = val.deptName
}
const updateVisible = (val) => {
    emit('updatetable')
}
const update = async() =>{
    let params = {
        bean:form.value,
        dataList:dataList.value
    }
    var res = await Api.audittable.updateReader.post(params);
    console.log(res)
    if (res.code == 200) {
        ElNotification.success({ title: '', message: '修改成功！', duration: 2000 });
        emit('updatetable', true);
    }
}


</script>
<style lang="less" scoped>

.borderNone {
    :deep(.el-input__wrapper) {
        box-shadow: 0 0 0 0px var(--el-input-border-color, var(--el-border-color)) inset;
        cursor: default;
        background-color: transparent; //背景颜色透明
        border-bottom: 1px solid #999;
        border-radius: 0;

        .el-input__inner {
            cursor: default !important;
        }
    }

    :deep(.el-textarea__inner) {
        box-shadow: 0 0 0 0px var(--el-input-border-color, var(--el-border-color)) inset;
        cursor: default;
        background-color: transparent; //背景颜色透明
        border-bottom: 1px solid #999;
        border-radius: 0;
    }
}
</style>



